/*
 * Project: Data Mining using SWARM
 * File: BTree.h
 * Author: Ivan Schwarz, Etienne Baali
 * Description: Definition of BTreeNode class
 *              Methods for manipulation with adjusted BTree.
 *              Method to find closed swarms(ObjectGrowth) via BTree.
 */


#ifndef DE7_BTREE
#define DE7_BTREE

#define OBJ_NUM 13 // Number of entities in dataset.

#include <vector>
#include <iostream>
#include <fstream> 

using namespace std;

/*
 * Class for one trajectory point
 */
class Cl_Object {

	int id;
	long double x;
	long double y;
public:
	inline int getId() { return id; }
	inline long double getX() { return x; }
	inline long double getY() { return y; }

	void setId(int id) { this->id = id; }
	void setX(long double x) { this->x = x; }
	void setY(long double y) { this->y = y; }


};

/*
 * Class representing node of B-Tree
 * Containing object database, timestamp database, cluster database
 * Containing information of (closed)swarms after performing Object Growth method
 * Could be also used for storing other kind of data
 */
class BTreeNode {

	int key;
	int level;
	bool cSwarm;
	vector<int> * oDatabase; 
	vector<int> * tDatabase; 
	vector<vector<vector<Cl_Object>>> * cDatabase;
	vector<int> keyVec;
	vector<BTreeNode*> childList;
public:
	BTreeNode(vector<int> * oData, vector<int> * tData, vector<vector<vector<Cl_Object>>> * cData);
	BTreeNode(vector<int> keyVec);
	BTreeNode();
	//~BTreeNode();

	inline int getLevel() { return level; }
	inline vector<int> getKeyVec() { return keyVec; }
	inline vector<BTreeNode*> getChildList() { return childList; }

	void setLevel(int level) { this->level = level; }

	void addChild(BTreeNode* child);
	void insert(BTreeNode * node);
	void objectGrowth(int mino, int mint);
	void readClustersFile(char * fileName);
	void printCDatabase();
};

/*
 * Function for rounding up floating point number. Used for setting the granularity of timestamps
 */
static long double rndup(long double n) 
{
	n *= 10000;
	int x = n;
	long double y = x;
	y /= 10000;
	return y;
}

#endif